import { CardAction } from "@renderer/components/ui/base/card";
import { cn } from "@renderer/lib/utils";
import { PenLine, Star, Trash2 } from "lucide-react";
import { useTranslation } from "react-i18next";
import { ButtonWithTooltip } from "./button-with-tooltip";

interface ActionGroupProps {
  className?: string;
  size?: "md" | "xs" | "sq-xs" | "sm" | "lg" | "sq-sm" | "sq-md" | "sq-lg";
  isCircle?: boolean;
  stared?: boolean;
  isCurrent?: boolean;
  starTooltip?: string;
  editTooltip?: string;
  deleteTooltip?: string;
  onEdit?: () => void;
  onDelete?: () => void;
  onStar?: () => void;
}

export function ActionGroup({
  className,
  isCircle = false,
  stared = false,
  isCurrent = false,
  starTooltip,
  editTooltip,
  deleteTooltip,
  onEdit,
  onDelete,
  onStar,
}: ActionGroupProps) {
  const { t } = useTranslation();

  return (
    <CardAction
      className={cn("flex h-full items-center justify-center", className)}
    >
      {/* Star */}
      {onStar && (
        <ButtonWithTooltip
          className={cn(
            "rounded-lg",
            "pressed:bg-transparent",
            isCurrent && "bg-accent hover:bg-accent",
          )}
          title={
            starTooltip || t("settings.model-settings.model-provider.star")
          }
          intent="plain"
          size="sq-xs"
          isCircle={isCircle}
          onClick={onStar}
        >
          <Star
            className={cn(
              "size-4",
              stared
                ? "fill-yellow-500 text-yellow-500"
                : isCurrent
                  ? "fill-accent-2 text-accent-2"
                  : "fill-accent-3 text-accent-3",
            )}
          />
        </ButtonWithTooltip>
      )}

      {/* Edit */}
      {onEdit && (
        <ButtonWithTooltip
          className={cn(
            "rounded-lg",
            "pressed:bg-transparent",
            isCurrent && "bg-accent hover:bg-accent-hover",
          )}
          title={
            editTooltip || t("settings.model-settings.model-provider.edit")
          }
          intent="plain"
          size="sq-xs"
          isCircle={isCircle}
          onClick={onEdit}
        >
          <PenLine
            className={cn("size-4", isCurrent && "text-accent-2")}
            strokeWidth={1.5}
          />
        </ButtonWithTooltip>
      )}

      {/* Delete */}
      {onDelete && (
        <ButtonWithTooltip
          className={cn(
            "rounded-lg",
            "pressed:bg-transparent",
            isCurrent && "bg-accent hover:bg-accent-hover",
          )}
          title={
            deleteTooltip || t("settings.model-settings.model-provider.delete")
          }
          intent="plain"
          size="sq-xs"
          isCircle={isCircle}
          onClick={onDelete}
        >
          <Trash2 className="size-4 text-danger-fg-2" />
        </ButtonWithTooltip>
      )}
    </CardAction>
  );
}
